package org.phantom.controller;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UnknownAccountException;
import org.phantom.securityframework.api.Account;
import org.phantom.securityframework.api.exception.AccountNotActivatedException;
import org.phantom.securityframework.api.exception.NullAccountException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("test")
@Controller
public class TestController {

	@RequestMapping(value="login",method=RequestMethod.POST)
	public ResponseEntity<String> login(String name,String pwd){
		Account account = new org.phantom.securityframework.api.domain.Account(name, pwd);
		try {
			account.login();
			return new ResponseEntity<String>(account.getAccountId(),HttpStatus.OK);
		} catch (NullAccountException e) {
			e.printStackTrace();
		} catch (UnknownAccountException e) {
			e.printStackTrace();
		} catch (AccountNotActivatedException e) {
			e.printStackTrace();
		} catch (AuthenticationException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<String>(HttpStatus.SERVICE_UNAVAILABLE);
	}
	
	@RequestMapping("test")
	public ResponseEntity<String> test(){
		return new ResponseEntity<String>("ok",HttpStatus.OK);
	}
}
